package io.github.talelin.latticy.common.pojo;

import java.awt.*;

/**
 * @authoer:wulongbo
 * @createDate:2022/7/28
 * @description:
 */
public class Distance {

    public static void main(String[] args) {
        Point p1 = new Point(10, 20);// 定义第一个点的坐标(10,20)
        Point p2 = new Point(70, 80);// 定义第二个点的坐标(70,80)
        //定位坐标

        System.out.println("p1的x坐标为" + p1.getX());
        System.out.println("p1的y坐标为" + p1.getY());
        System.out.println("p2的x坐标为" + p2.getX());
        System.out.println("p2的y坐标为" + p2.getY());
        // 计算两点间距离公式
        double distance = Math.sqrt(Math.abs((p1.getX() - p2.getX()) * (p1.getX() - p2.getX()) + (p1.getY() - p2.getY()) * (p1.getY() - p2.getY())));
        System.out.println("两点间的距离是:" + distance);

        // 计算斜率
        double kx = (p2.getX() - p1.getX()) / distance;
        double ky = (p2.getY() - p1.getY()) / distance;

        //c为在两点间移动的距离
        int c = 3;

        // 计算现在应该到达的距离
        float x = (float) (p1.getX() + c * kx);
        float y = (float) (p1.getY() + c * ky);
        System.out.println("移动后的坐标x：" + x);
        System.out.println("移动后的坐标y：" + y);

    }
}
